<?php
/**
 * Created by PhpStorm.
 * User: simon
 * Date: 2016/11/18
 * Time: 11:33
 */

namespace App\Utils;


class SecretChecker
{

    /**
     * @param \Illuminate\Http\Request $request
     * @return bool
     */
    public static function isSafe($request)
    {
        $ip = $request->getClientIp();
        $whiteIps = env("WHITE_IPS");
        if (!empty($whiteIps)) {
            $matrix = explode(",", $whiteIps);
            if (in_array($ip, $matrix)) {
                return true;
            }
        }
        $configCode = env("ACCESS_CODE");
        if (!empty($configCode)) {
            if ($configCode === $request->get("access_code")) {
                return true;
            }
        }
        return false;
    }
}